package com.whsm.admin.table;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whsm.admin.domain.User;
import com.whsm.admin.service.MyUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class TableController {


    @Autowired
    MyUserServiceImpl  myUserService;

    @GetMapping("/basic_table")
    public String basic_table(){
        return "table/basic_table";
    }

    @GetMapping("/dynamic_table")
    public String dynamic_table(@RequestParam(value = "pn",defaultValue = "1") Integer pn, Model model){
        /*List<User> users = Arrays.asList(new User("zhangsan", "123456"),
                new User("lisi", "123456"),
                new User("wangwu", "123456"),
                new User("zhaoliu", "123456"));
        model.addAttribute("users",users);*/
        Page<User> userPage = new Page<>(pn, 2);
        Page<User> page = myUserService.page(userPage, null);
        List<User> list = myUserService.list();
        long current = page.getCurrent();
        model.addAttribute("page",page);

        return "table/dynamic_table";
    }

    @GetMapping("/editable_table")
    public String editable_table(){
        return "table/editable_table";
    }

    @GetMapping("/pricing_table")
    public String pricing_table(){
        return "table/pricing_table";
    }

    @GetMapping("/responsive_table")
    public String responsive_table(){
        return "table/responsive_table";
    }

}
